﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;


namespace QLMBMT
{
    public partial class FrmTKMatHang : DevExpress.XtraEditors.XtraForm
    {
        private DataSet ds = new DataSet();
        private DataTable dt = new DataTable();
        private SqlDataAdapter da = new SqlDataAdapter();
        private SqlCommand com = new SqlCommand();
        classConnection _classConnection = new classConnection();
        public FrmTKMatHang()
        {
            InitializeComponent();
        }

        private void FrmTKMatHang_Load(object sender, EventArgs e)
        {
            com = new SqlCommand("Select * from LOAI_HANG", _classConnection.con);
            da = new SqlDataAdapter();
            ds = new DataSet();
            da.SelectCommand = com;
            da.Fill(ds);
            GridLookUpEdit2.DataSource = ds.Tables[0];
        }

        private void btnTK_Click(object sender, EventArgs e)
        {
            try
            {
                // Đổ dữu liệu vào data gridview
                com = new SqlCommand("Select * from MAT_HANG where TENHANG =@TENHANG", _classConnection.con);
                com.Parameters.Add("TENHANG", SqlDbType.VarChar).Value = txtTenNV.Text;
                da = new SqlDataAdapter();
                da.SelectCommand = com;
                ds = new DataSet();
                da.Fill(ds);
                gridControlTKKH.DataSource = ds.Tables[0];
                dt = ds.Tables[0];
                if (dt == null || dt.Rows.Count == 0)
                {
                    MessageBox.Show("Không tìm thấy dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                txtTenNV.DataBindings.Clear();
                txtTenNV.DataBindings.Add("EditValue", gridControlTKKH.DataSource, "TENHANG");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            };
        }
    }
}